package modelPackage;

import java.awt.Image;
import java.awt.Point;
import java.awt.Toolkit;

public class Player extends Character {

	//THIS SHOULD BE A QUALITY OF THE MAP, NOT OF THE PLAYER.
	static final Point initposition = new Point(60,60);
	
	//Each player knows a map.  That is how the view knows what to draw.
	private Map3D map;
	
	//This would be used if we had multiplayer implemented.
	private String ID;
	
	// Here are some statistics.
	// Eventually maybe there'll be some statistics in there or something.
	private int lives;
	
	// This boolean is used to make it so that the player can't double jump.
	private boolean hasJumped = false;
	
	//Velocity in the X and Z planes should be the same, and a constant.
	static protected double vx = 0.75;
	static protected double vz = 0.75;
	
	//This is used to control the pausing of the game.
	private boolean paused;
	private int returnTo;
	
	
	
	/*
	 * Here are the methods for a player.  They begin with a constructor.
	 * */
	
	public Player(String name) {
		super(50, 50, initposition);
		ID = name;		
		lives = 5;
		initializeAnimations();
		paused = false;
		returnTo = 2;
	}
	
	

	
	/*
	 * Nikhil wrote this.
	 * */
	/**
	 * This is called when player is supposed to be killed!
	 */
	@Override
	public void collide() {
		//setActive(false);
		lives--;
		position.setPosition(new Point(100, 100), 0);
	}
	
	
	
	/*
	 * This section exists because we need to control the jumpery, and disallow double jumpery and whatnot.
	 * */
	public int updateYPosition(long elapsedTime) {
		int ans = super.updateYPosition(elapsedTime);

		if (super.getYVelocity() > 0) {
			hasJumped = false;
		}
		
		return ans;
	}
	
	public boolean getJumped() {
    	return hasJumped;
    }
    
    public void setJumped(boolean jump) {
    	hasJumped = jump;
    }
	
    
    /*
     * This needs to be here because velocities are different for players and bears.
     */
    public int updateXPosition(long elapsedTime){
		return super.updateXPosition(elapsedTime, vx);
	}
	public int updateZPosition(long elapsedTime) {
		return super.updateZPosition(elapsedTime, vz);
	}
	
	/*
	 * Some methods which are specific to players.  Because players are in control of stuff.
	 * */
	public void setMap(Map3D m) {
		map = m;
	}
	public Map getMap() {
		return map.get2DMap();
	}	
	public Map3D get3DMap() {
		return map;
	}
	
	
	public String getID() {
		return ID;
	}
	
    
    
	/*
	 * This is where we provide getters and setters for player statistics.
	 * */
	public int getRemainingLives(){
    	return lives;
    }
    
    public void setRemainingLives(int l) {
    	lives = l;
    }
    
    
    
    /*
     * This section deals with animations and images and stuff.
     * */
    
	/**
	 * Makes all the animations, and adds them to the animation lists.
	 */
    @Override
	public void initializeAnimations() {
		Animation only = new Animation("only");
		
		Image only0 = loadImage("images/Player/player0.png");
		Image only1 = loadImage("images/Player/player1.png");
		Image only2 = loadImage("images/Player/player2.png");
		Image only3 = loadImage("images/Player/player3.png");
		Image only4 = loadImage("images/Player/player4.png");
		Image only5 = loadImage("images/Player/player5.png");
		Image only6 = loadImage("images/Player/player6.png");
		Image only7 = loadImage("images/Player/player7.png");
		Image only8 = loadImage("images/Player/player8.png");
		Image only9 = loadImage("images/Player/player9.png");
		Image only10 = loadImage("images/Player/player10.png");
		Image only11 = loadImage("images/Player/player11.png");
		
		only.addFrame(only0, 175);
		only.addFrame(only1, 175);
		only.addFrame(only2, 175);
		only.addFrame(only3, 175);
		only.addFrame(only4, 175);
		only.addFrame(only5, 175);
		only.addFrame(only6, 175);
		only.addFrame(only7, 175);
		only.addFrame(only8, 175);
		only.addFrame(only9, 175);
		only.addFrame(only10, 175);
		only.addFrame(only11, 175);
		
		super.addAnimation(only);
		
		super.setAnimation("only");
		
	}
	
    @Override
	public void updateAnimation(Long elapsedTime) {
		super.updateAnimation(elapsedTime);
	}
    
	private Image loadImage(String filename) {
		return Toolkit.getDefaultToolkit().getImage(filename);
	}

	
	
	
	/*
	 * This stuff is used to make the game pause.  And return from pause.
	 * */
	
	public void setPaused(boolean b) {
		paused = b;
	}
	
	public boolean getPaused() {
		return paused;
	}
	
	public void setReturnTo(int i) {
		returnTo = i;
	}
	
	public int getReturnTo() {
		return returnTo;
	}
	
	


	/*
	 * These functions are necessary because of the way it's written. Which is kind of poorly.
	 */
	@Override
	public double getXVelocity() {
		return vx;
	}

	@Override
	public double getZVelocity() {
		return vz;
	}
    
}